package ee.ttu.karileet.serviceshop.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ee.ttu.karileet.serviceshop.dao.EmployeeDAO;
import ee.ttu.karileet.serviceshop.dao.PersonDAO;
import ee.ttu.karileet.serviceshop.bo.EmployeeBO;
import ee.ttu.karileet.serviceshop.model.Employee;
import ee.ttu.karileet.serviceshop.service.EmployeeService;


@Service("employeeService")
public class EmployeeServiceImpl implements EmployeeService {

	@Autowired
	private EmployeeDAO employeeDao;
	@Autowired
	private PersonDAO personDao;
	@Override
	@Transactional
	public void insertEmployee(EmployeeBO object) {
//		employeeDao.insertEmployeeBO(object);
		//TODO: implement
	}

	@Override
	@Transactional
	public List<EmployeeBO> getEmployees() {
		List<Employee> list = employeeDao.getEmployees();
		List<EmployeeBO> bos = new ArrayList<EmployeeBO>();
		for (Employee e : list) {
			bos.add(getEmployeeById(e.getEmployee()));
		}
		return bos;
	}

	@Override
	@Transactional
	public EmployeeBO getEmployeeById(long id) {
		EmployeeBO e = new EmployeeBO();
		Employee emp = employeeDao.getEmployeeById(id);
		e.setEmployee(emp.getEmployee());
		e.setPerson(personDao.getPersonById(id));
		e.setActive(emp.getActive());
		
		return e;
	}

}
